package com.le.tester.javaThink.fifth.chapter24_ConcurrentProgramming;

import java.util.List;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.stream.Collectors;
import java.util.stream.IntStream;

/**
 * createTime：2021/8/18 11:31
 * description：QuittingTasks
 */
public class QuittingTasks {
    public static final int COUNT = 150;

    public static void main(String[] args) throws InterruptedException {
        ExecutorService service = Executors.newCachedThreadPool();

        List<QuittableTask> tasks = IntStream.range(1, COUNT)
                .mapToObj(QuittableTask::new)
                .peek(service::execute)
                .collect(Collectors.toList());
        Thread.sleep(1000);
        tasks.forEach(QuittableTask::quit);
        service.shutdown();
    }
}
